﻿using System;
using System.Data;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FashionShop.Models;

namespace FashionShop.Areas.Home.Controllers
{
    public class BrandController : HomeAppController
    {
        //
        // GET: /Home/Brand/

        public ActionResult Index(string url)
        {
            var brand = db.Brand.Where(m => m.URL == url).FirstOrDefault();
            if (brand == null)
                return HttpNotFound();
            ViewBag.Brand = brand;
            //New Products
            var product = db.Product.Include(p => p.Brand).Include(p => p.ProductCatalogue);
            ViewBag.Products = product.OrderByDescending(m => m.Created).Where(m => m.BrandID == brand.BrandID).Take(16).ToList();
            //Quan ao
            var underwear = db.Product.Include(p => p.Brand).Include(p => p.ProductCatalogue);
            ViewBag.UnderwearProducts = underwear.OrderByDescending(m => m.Created)
                .Where(m => m.ProductCatalogueID == 8 && m.BrandID == brand.BrandID)
                .ToList();

            //QUan
            var pants = db.Product.Include(p => p.Brand).Include(p => p.ProductCatalogue);
            ViewBag.PantProducts = pants.OrderByDescending(m => m.Created)
                .Where(m => m.ProductCatalogueID == 1 && m.BrandID == brand.BrandID)
                .ToList();
            //Ao
            var coat =
                db.Product.Include(p => p.Brand).Include(p => p.ProductCatalogue);
            ViewBag.CoatProducts = coat.OrderByDescending(m => m.Created)
                .Where(m => m.ProductCatalogueID == 2 && m.BrandID == brand.BrandID)
                .Take(5)
                .ToList();

            return View();
        }

    }
}
